#include "moreitemdelegate.h"
#include "moreitemwidget.h"
#include <QApplication>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QPainter>
#include <QPushButton>
#include <QStyle>
#include <QStyleOptionButton>

MoreItemDelegate::MoreItemDelegate(LiveRecorderView* view, QObject* parent)
    : QStyledItemDelegate(parent), view_(view)
{
}

void MoreItemDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
                             const QModelIndex& index) const
{
    QStyleOptionViewItem opt = option;
    initStyleOption(&opt, index);
    opt.state &= ~QStyle::State_HasFocus;
    QStyledItemDelegate::paint(painter, option, index);

    // const int HOME_WIDTH = 60;
    // const int MORE_WIDTH = 40;
    // const int SPACING = 6;
    // const int HEIGHT = 24;

    // int left = opt.rect.left() + (opt.rect.width() - HOME_WIDTH) / 2;
    // int top = opt.rect.top() + (opt.rect.height() - HEIGHT) / 2;

    // QStyleOptionButton home;
    // home.text = tr("Home");
    // home.rect = QRect(left, top, HOME_WIDTH, HEIGHT);
    // QApplication::style()->drawControl(QStyle::CE_PushButton, &home, painter, opt.widget);

    // QStyleOptionButton more;
    // more.text = tr("...");
    // more.rect = QRect(left + HOME_WIDTH + SPACING, top, MORE_WIDTH, HEIGHT);
    // QApplication::style()->drawControl(QStyle::CE_PushButton, &more, painter, opt.widget);
}

QWidget* MoreItemDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option,
                                        const QModelIndex& index) const
{
    Q_UNUSED(option);
    return new MoreItemWidget(view_, 0, parent);
}

void MoreItemDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option,
                                            const QModelIndex& index) const
{
    editor->setGeometry(option.rect);
}
